import Config from "../main.config";
import Ajax from "../utils/Ajax";
module.exports = {
    /*
    * 获取发布人列表
    * */
    getPublisherList: async function (data = {}) {
        let url = Config.api.positionPublisher;
        let res = await Ajax.request({
            method: "POST",
            url,
            data
        })
        return res.map(function (item) {
            return {
                text: item.className,
                value: item.classNo,
                industryName: item.industryName,
                industryNo: item.industryNo
            }
        })
    },

    /*
    * 获取招聘列表信息
    * */
    getRecruitmentList: async function (data = {}) {
        let url = Config.api.positionList;
        let res = await Ajax.request({
            method: "POST",
            url,
            data
        })
        return {
            count: res.count,
            data: res.data.map(function (item) {
                let tags = [];
                let logoUrl = Config.api.downLoad + "?fileId=" + (item.logo || item.companyLogo)
                item.nature ? tags.push(item.nature) : null;
                item.schooling ? tags.push(item.schooling) : null;
                return {
                    id: item.id,
                    name: item.name,
                    type: item.type,
                    salary: item.salary,
                    tags,
                    logo: logoUrl,
                    publisherName: item.staffName ? (item.staffName + " - " + item.position + " - " + item.deptName) : item.companyName,
                    resumeCount: item.resumeCount,
                    city: item.city
                }
            })
        }
    },

    /*
    * 发布招聘信息
    * */
    add: async function (data = {}) {
        let url = Config.api.positionAdd;
        return await Ajax.request({
            method: "POST",
            url,
            data
        })
    },

    /*
    * 招聘信息编辑
    * */
    edit: async function (data = {}) {
        let url = Config.api.positionEdit;
        return await Ajax.request({
            method: "POST",
            url,
            data
        })
    },

    /*
    * 删除招聘信息
    * */
    deleteItem: async function (id) {
        let url = Config.api.positionDelete;
        return await Ajax.request({
            method: "POST",
            url,
            data: {id}
        })
    },

    /*
    * 获取详情
    * */
    getDetail: async function (data = {}) {
        let url = Config.api.positionDetail;
        let res = await Ajax.request({
            method: "POST",
            url,
            data
        })
        let tags = [];
        res.nature ? tags.push(res.nature) : null;
        res.schooling ? tags.push(res.schooling) : null;
        res.tags = tags;
        return res
    },

    /*
    * 获取简历投递列表
    * */
    getDeliverList: async function (data = {}) {
        let url = Config.api.positionDeliverList;
        let res = await Ajax.request({
            method: "POST",
            url,
            data
        })
        return {
            count: res.count,
            data: res.data
        }
    },

    /*
    * 投递招聘信息
    * */
    addDeliver: async function (data = {}) {
        let url = Config.api.positionDeliver;
        return await Ajax.request({
            method: "POST",
            url,
            data
        })
    },

    /*
    * 获取发布职位列表
    * */
    getPublishPositionList: async function (data = {}) {
        let url = Config.api.positionPublishList;
        return await Ajax.request({
            method: "POST",
            url,
            data
        })
    }

}